feat: Use Lock/Unlock signal from org.freedesktop.login1.Session for session lock#83
feat: Use Lock/Unlock signal from org.freedesktop.login1.Session for session lock#83calsys456 wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
…session lock This is more portable and robustic. Refined the logging system to make them more informative as well.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: calsys456 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @calsys456. Thanks for your PR. I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Reviewer's GuideImplements session lock/unlock via org.freedesktop.login1 instead of custom LoginSucceeded signaling and refines daemon logging for login, session management, and greeter communication. Sequence diagram for session lock via org.freedesktop.login1sequenceDiagram
actor Greeter
participant SocketServer
participant Display
participant Login1Manager as OrgFreedesktopLogin1ManagerInterface
Greeter->>SocketServer: send GreeterMessages::Lock(id)
SocketServer->>SocketServer: read id from socket
SocketServer->>SocketServer: qDebug Message received from greeter: Lock
SocketServer->>Display: emit lock(socket, id)
Display->>Display: qDebug Lock requested for session id
Display->>Login1Manager: create with Logind::serviceName, Logind::managerPath, system bus
Display->>Login1Manager: LockSession(QString::number(id))
Sequence diagram for session unlock via org.freedesktop.login1sequenceDiagram
actor Greeter
participant SocketServer
participant Display
participant Login1Manager as OrgFreedesktopLogin1ManagerInterface
participant VirtualTerminal
Greeter->>SocketServer: send GreeterMessages::Unlock(user, password)
SocketServer->>SocketServer: read user, password from socket
SocketServer->>Display: emit unlock(socket, user, password)
alt user is dde
Display->>Display: check user == dde
Display-->>SocketServer: emit loginFailed(socket, user)
else normal user
Display->>Display: qInfo Start identify user
Display->>Display: find Auth in auths with auth->user == user and auth->xdgSessionId > 0
alt matching Auth found
Display->>Login1Manager: create with Logind::serviceName, Logind::managerPath, system bus
Display->>Login1Manager: UnlockSession(QString::number(auth->xdgSessionId))
Display->>VirtualTerminal: jumpToVt(auth->tty, false)
Display->>Display: qInfo Successfully identified user
else no matching Auth
Display->>Display: qWarning No active session found for user
Display-->>SocketServer: emit loginFailed(socket, user)
end
end
Updated class diagram for Display, SocketServer and TreelandDisplayServerclassDiagram
class Display {
+connected(socket: QLocalSocket*)
+login(socket: QLocalSocket*, user: QString, password: QString, session: Session)
+logout(socket: QLocalSocket*, id: int)
+lock(socket: QLocalSocket*, id: int)
+unlock(socket: QLocalSocket*, user: QString, password: QString)
<<signal>> loginFailed(socket: QLocalSocket*, user: QString)
-auths: QList~Auth*~
-m_socketServer: SocketServer*
}
class SocketServer {
+informationMessage(socket: QLocalSocket*, message: QString)
+loginFailed(socket: QLocalSocket*, user: QString)
<<signal>> login(socket: QLocalSocket*, user: QString, password: QString, session: Session)
<<signal>> logout(socket: QLocalSocket*, id: int)
<<signal>> lock(socket: QLocalSocket*, id: int)
<<signal>> unlock(socket: QLocalSocket*, user: QString, password: QString)
<<signal>> connected(socket: QLocalSocket*)
}
class TreelandDisplayServer {
+start(socketServer: SocketServer*)
+stop()
+activateUser(user: QString, xdgSessionId: int)
+onLoginFailed(user: QString)
-m_socketServer: SocketServer*
-m_greeterSockets: QList~QLocalSocket*~
}
class GreeterMessages {
<<enum>>
+Lock
+Unlock
+Logout
+Suspend
+Hibernate
+HybridSleep
+BackToNormal
}
class DaemonMessages {
<<enum>>
+HostName
+Capabilities
+LoginFailed
+InformationMessage
+UserActivateMessage
}
class OrgFreedesktopLogin1ManagerInterface {
+LockSession(id: QString)
+UnlockSession(id: QString)
}
Display --> SocketServer : uses
TreelandDisplayServer --> SocketServer : uses
Display --> OrgFreedesktopLogin1ManagerInterface : locks_unlocks_sessions
SocketServer --> GreeterMessages : parses
SocketServer --> DaemonMessages : sends
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new lock/unlock paths call login1
LockSession/UnlockSessionsynchronously without checking for DBus errors or unavailable logind; consider usingQDBusPendingReplyor checking the return value and logging/handling failures to avoid silently ignoring issues. - Logging has been made more verbose but is a mix of
qDebug,qInfo, andqWarningfor similar events (e.g., logout vs. lock vs. login); it may be worth standardizing the log levels and including consistent identifiers (session id, user, tty) to make traces easier to follow.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new lock/unlock paths call login1 `LockSession`/`UnlockSession` synchronously without checking for DBus errors or unavailable logind; consider using `QDBusPendingReply` or checking the return value and logging/handling failures to avoid silently ignoring issues.
- Logging has been made more verbose but is a mix of `qDebug`, `qInfo`, and `qWarning` for similar events (e.g., logout vs. lock vs. login); it may be worth standardizing the log levels and including consistent identifiers (session id, user, tty) to make traces easier to follow.
## Individual Comments
### Comment 1
<location> `src/daemon/Display.cpp:307-310` </location>
<code_context>
} else if (session.xdgSessionType() == QLatin1String("x11")) {
auth->type = X11;
+ qInfo() << "Stopping Treeland";
daemonApp->treelandConnector()->disconnect();
m_treeland->stop();
QThread::msleep(500); // give some time to treeland to stop properly
// Start X server
</code_context>
<issue_to_address>
**suggestion:** Consider extracting the Treeland shutdown sequence into a helper to avoid duplication.
The `disconnect()`, `m_treeland->stop()`, and `QThread::msleep(500)` pattern is duplicated in both the X11 and non-X11 paths (now with an added log line). Centralizing this sequence in a small helper like `stopTreeland()` would make future changes (e.g., timeout or additional cleanup) safer and keep the behavior aligned across branches.
Suggested implementation:
```cpp
auth->type = X11;
stopTreeland();
// Start X server
```
```cpp
} else {
auth->type = Wayland;
stopTreeland();
```
To fully implement the refactoring, you should also:
1. **Implement the helper in `src/daemon/Display.cpp`**, as a `Display` member function, somewhere near other small helpers:
```cpp
void Display::stopTreeland()
{
qInfo() << "Stopping Treeland";
daemonApp->treelandConnector()->disconnect();
if (m_treeland) {
m_treeland->stop();
}
// Give some time to Treeland to stop properly
QThread::msleep(500);
}
```
2. **Declare the helper in `src/daemon/Display.h`** in the `Display` class, preferably in the `private:` section:
```cpp
private:
void stopTreeland();
// ... existing members
```
3. If `QThread` is not already included in `Display.cpp`, ensure the correct include exists at the top of the file:
```cpp
#include <QThread>
```
These changes will centralize the Treeland shutdown sequence, keep the logging consistent, and make future adjustments (e.g., changing the timeout or adding extra cleanup) safer and easier.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Paired with linuxdeepin/treeland#735 |
This is more portable and robustic.
Refined the logging system to make them more informative as well.
Summary by Sourcery
Integrate session lock and unlock handling with logind and clean up obsolete login success signaling while improving daemon logging clarity.
New Features:
Enhancements: